﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;

namespace DAL
{
    public class PersonalDAL
    {
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="pe"></param>
        /// <returns></returns>
        public static Personalmodel login(string tel, string pwd)
        {
            List<Personalmodel> list = new List<Personalmodel>();
            string sql = "select * from Personal where tel=@tel and pwd=@pwd";
            SqlParameter[] para = new SqlParameter[] {
                new   SqlParameter("@tel",tel),
                  new   SqlParameter("@pwd",pwd)
            };
            SqlDataReader reader = DBhelper.ExecuteReaders(sql, para);
            
            while (reader.Read())
            {
                Personalmodel pes = new Personalmodel();
                pes.tel = reader["tel"].ToString();
                pes.pwd = reader["pwd"].ToString();
                pes.nameper = reader["nameper"].ToString();
                list.Add(pes);
            }
            reader.Close();
            return list[0];
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="pe"></param>
        /// <returns></returns>
        public static int register(Personalmodel pe)
        {
            string sql = string.Format("insert into Personal values(@nameper,@nid,@Sex,@tel,@pwd,null)");
            SqlParameter[] para = new SqlParameter[] {
                 new   SqlParameter("@nameper",pe.nameper),
                  new   SqlParameter("@nid",pe.nid),
                  new   SqlParameter("@Sex",pe.Sex),
                  new   SqlParameter("@tel",pe.tel),
                   new   SqlParameter("@pwd",pe.pwd),

            };
            int reader = DBhelper.executenonquery(sql, para);
            return reader;
        }
    }
}
